<?php 
header("Content-type:text/html;charset=utf-8");
$conn = mysql_connect('localhost','root','') Or die('数据库无法连接');
mysql_select_db('neu-video')  Or die('数据库不存在');
mysql_query('set names utf8'); 

$sql_admins = 'select * from admins';
$result_admins = mysql_query($sql_admins);

$sql_comments = 'select *from comments';
$result_comments= mysql_query($sql_comments);

$sql_levels = 'select *from levels';
$result_levels= mysql_query($sql_levels);

//$sql_levels = 'select levels.*,comments.* from levels left join comments on levels.uid = comments.uid' ;
//$result_levels = mysql_query($sql_levels);
//$levels = fetch_array($result_levels);

echo '<table border="1">';
$admins = fetch_array($result_admins);
echo '<caption>管理员表</caption>';
echo '<tr><th>管理员ID</th><th>管理员名</th><th>密码</th></tr>';
foreach ($admins as $one )
{
	echo '<tr>';
	echo '<td>'.$one ['adminid'].'</td>';
	echo '<td>'.$one ['adminname'].'</td>';
	echo '<td>'.$one ['password'].'</td>';
	echo '</tr>';
}
echo '<table border = "1">';
$comments = fetch_array($result_comments);
echo '<table border = "1">';
echo '<caption>评论信息表</caption>';
echo '<tr><th>评论ID</th>
      <th>评论内容</th>
      <th>评论日期</th>
      <th>评论用户</th>
      <th>评论视频</th></tr>';

foreach($comments as $index =>$one )
{
	echo '<tr>';
	echo '<td>'.($index+1).'</td>';
	echo '<td>'.$one ['cid'].'</td>';
	echo '<td>'.$one ['content'].'</td>';
	echo '<td>'.$one ['cdate'].'</td>';
	echo '<td>'.$one ['uid'].'</td>';
	echo '<td>'.$one ['vid'].'</td>';
	echo '</tr>';
}
echo '</table>';

$levels = fetch_array($result_levels);
echo '<table border = "1">';
echo '<caption>视频评分表</caption>';
echo '<tr><th>级别ID</th><th>视频ID</th><th>打分用户</th>
		  <th>评分</th></tr>';
foreach ($levels as $one ) 
{
	echo '<tr>';
	echo '<td>'.$one['lid'].'</td>';
	echo '<td>'.$one['vid'].'</td>';
	echo '<td>'.$one['uid'].'</td>';
	echo '<td>'.$one['score'].'</td>';
	echo '<tr>';
}
echo '</table>';

function fetch_array($Results) {
	$arrs = array();
	while($Results && ($row = mysql_fetch_assoc($Results) )!==FALSE ){ 
		$arrs[]=$row;
}
	return $arrs;
}



?>
